package com.example.milimili;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

public class MainFragment extends Fragment {
    private EditText searchText;
    private ImageButton searchBtn,menuBtn;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.mainlayout,container,false);
        searchText=view.findViewById(R.id.searchText);
        searchBtn=view.findViewById(R.id.searchButton);
        menuBtn=view.findViewById(R.id.menuButton);
        menuBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getContext(),TabChooseActivity.class);
                getContext().startActivity(intent);
            }
        });
        TabLayout tl = view.findViewById(R.id.tabLayout);
        ViewPager2 viewPager2 = view.findViewById(R.id.viewPager);
        viewPager2.setAdapter(new FragmentAdapter(getActivity()));
        TabLayoutMediator tab = new TabLayoutMediator(tl, viewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
//                娱乐、军事、教育、文化、健康、财经、体育、汽车、科技、社会
                switch (position){
                    case 0:
                        tab.setText("娱乐");
                        break;
                    case 1:
                        tab.setText("军事");
                        break;
                    case 2:
                        tab.setText("教育");
                        break;
                    case 3:
                        tab.setText("文化");
                        break;
                    case 4:
                        tab.setText("健康");
                        break;
                    case 5:
                        tab.setText("财经");
                        break;
                    case 6:
                        tab.setText("体育");
                        break;
                    case 7:
                        tab.setText("汽车");
                        break;
                    case 8:
                        tab.setText("科技");
                        break;
                    case 9:
                        tab.setText("社会");
                        break;
                }
            }
        });
        tab.attach();
        return view;
    }
}
